package com.xiaozhen.coap.resource;

import org.eclipse.californium.core.CoapResource;
import org.eclipse.californium.core.coap.CoAP;
import org.eclipse.californium.core.server.resources.CoapExchange;

/**
 * HISTORY
 *
 * @author zhenweisheng
 * @date 2021/10/13 16:16
 * @description:
 */
public class TestResource extends CoapResource {


    public TestResource(String name) {
        super(name);
        getAttributes().setTitle("test");
    }

    @Override
    public void handleGET(CoapExchange exchange) {
        System.out.println("get start");
        exchange.respond("got");
    }

    @Override
    public void handlePOST(CoapExchange exchange) {
        System.out.println("post start");
        String result = exchange.getRequestText();
        System.out.println("the received text:" + result);
        //exchange.respond(ResponseCode.CHANGED);
        exchange.respond(CoAP.ResponseCode.CHANGED, "good");
    }
}
